//
//  MineDataController.m
//  village_ios
//
//  Created by mac on 2019/8/11.
//  Copyright © 2019 com.sw.village. All rights reserved.
//

#import "MineDataController.h"
#import "UIAlertController+Blocks.h"
#import "UserInfo.h"

@interface MineDataController ()

@property (weak, nonatomic) IBOutlet UITextField *addressTextField;
@property (weak, nonatomic) IBOutlet UITextField *villageJobTextField;
@property (weak, nonatomic) IBOutlet UITextField *wechatTextField;
@property (weak, nonatomic) IBOutlet UITextField *qqTextField;
@property (weak, nonatomic) IBOutlet UITextField *douyinTextField;

@end

@implementation MineDataController

- (void)viewDidLoad {

    [super viewDidLoad];
    [self loadUserInfo];
}
- (void)loadUserInfo {
    self.addressTextField.text = self.userInfo.address;
    self.villageJobTextField.text = self.userInfo.villageJob;
    self.wechatTextField.text = self.userInfo.wechat;
    self.qqTextField.text = self.userInfo.qq;
    self.douyinTextField.text = self.userInfo.douyin;
}
- (IBAction)toDone:(id)sender {

    [UIAlertController showAlertInViewController:self withTitle:@"是否确认" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger buttonIndex) {

        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        if (self.addressTextField.text) {
            [params addEntriesFromDictionary:@{@"address":self.addressTextField.text}];
        }
        if (self.villageJobTextField.text) {
            [params addEntriesFromDictionary:@{@"villageJob":self.villageJobTextField.text}];
        }
        if (self.wechatTextField.text) {
            [params addEntriesFromDictionary:@{@"wechat":self.wechatTextField.text}];
        }
        if (self.qqTextField.text) {
            [params addEntriesFromDictionary:@{@"qq":self.qqTextField.text}];
        }
        
        if (self.douyinTextField.text) {
            [params addEntriesFromDictionary:@{@"douyin":self.douyinTextField.text}];
        }
        [SYProgressHUD show];
        [APIManager requestWithUrlString:@"api/user/editItem" params:params method:@"POST" success:^(id response) {

            [SYProgressHUD showSuccessText:@"保存成功"];
            [self.navigationController popViewControllerAnimated:YES];
        } failure:^(NSError *error) {
            [SYProgressHUD showInfoText:@"保存失败"];

        }];

    }];

}
@end
